ArrayList in Java [on hold]

Posted by JNL on Programmers See other posts from Programmers or by JNL
Published on 2013-06-26T14:59:09Z Indexed on 2013/06/26 16:28 UTC
Read the original article Hit count: 180

Filed under:
|

I was implementing a program to remove the duplicates from the 2 character array. I implemented these 2 solutions, Solution 1 worked fine, but Solution 2 given me UnSupportedoperationException. I am wonderring why i sthat so?

The two solutions are given below;

public void getDiffernce(Character[] inp1, Character[] inp2){

// Solution 1:

    // **********************************************************************************

    List<Character> list1 = new ArrayList<Character>(Arrays.asList(inp1));
    List<Character> list2 = new ArrayList<Character>(Arrays.asList(inp2));
    list1.removeAll(list2);

    System.out.println(list1);
    System.out.println("*********************************************************************************");

// Solution 2:

    Character a[] = {'f', 'x', 'l', 'b', 'y'};
    Character b[] = {'x', 'b','d'};

    List<Character> al1 = new ArrayList<Character>(); 
    List<Character> al2 = new ArrayList<Character>(); 
    al1 = (Arrays.asList(a)); System.out.println(al1);
    al2 = (Arrays.asList(b)); System.out.println(al2);  
    al1.removeAll(al2);         // retainAll(al2);      
    System.out.println(al1);


    }

© Programmers or respective owner

Related posts about java

Related posts about collections